package com.wcj.queue;

import java.util.ArrayList;

/**
 * 尾指针指向的位置，不存元素，留作约定
 */
public class MyCircularQueue {
    private int[] data;
    int head;
    int tail;

    public MyCircularQueue(int k) {
        data = new int[k + 1];
        head = 0;
        tail = 0;
    }

    public boolean enQueue(int value) {
        if (isFull()){
            return false;
        }
        data[tail] = value;
        tail = (tail+1)%data.length;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()){
            return false;
        }
        head = (head+1)%data.length;
        return true;
    }

    public int Front() {
        if (isEmpty()){
            return -1;
        }
        return data[head];
    }

    public int Rear() {
        if (isEmpty()){
            return -1;
        }
        return data[(tail - 1 + data.length) % data.length];
    }

    public boolean isEmpty() {
        return tail==head;
    }

    public boolean isFull() {
        return (tail+1)%data.length==head;
    }
}
